﻿using Carer.Crm.Utility;
using Carer.Data;
using NLog;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Carer.Crm.Services
{
    public sealed class CrewTypeService : BaseService
    {
        private static Logger _logger = LogManager.GetLogger("CrewTypeService");
        public IList<CrewType> GetAllCrewTypes(int? uid)
        {
            string sSql = @"SELECT [Id]
                  ,[Name]
                  ,[Ratio]
                  ,[Order]
                  ,[UnitId]
              FROM [dbo].[CrewType]
              WHERE 1=1 ";
            if (uid.HasValue)
            {
                sSql += " AND [UnitId]=" + uid.Value;
            }
            IList<CrewType> result = new List<CrewType>();
            try
            {
                DataTable dt = SqlHelper.ExecuteDataTable(this.CONN_STR, System.Data.CommandType.Text, sSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        result.Add(new CrewType()
                        {
                            Id = row["Id"].ToGetValue(0),
                            Name = row["Name"].ToGetValue(string.Empty),
                            Ratio = row["Ratio"].ToGetValue(0D),
                            Order = row["Order"].ToGetValue(0),
                            UnitId = row["UnitId"].ToGetValue(0)
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "GetAllCrewTypes报错:");
            }

            return result;
        }
    }
}
